package org.example.aop.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


//如果没有这个注释，是按照名称进行排序
@Order(1)
@Slf4j
@Component
@Aspect
public class AspectDemo1 {

    @Around("execution(* org.example.aop.controller.*.*(..))")
    //建议不要使用void，使用void可能会出现显示结果的情况
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("AspectDemo1 before around...");
        Object object =  joinPoint.proceed();
        log.info("AspectDemo1 after before...");
        return object;
    }

    @Before("execution(* org.example.aop.controller.*.*(..))")
    public void before(){
        log.info("AspectDemo1 before ...");
    }

    @After("execution(* org.example.aop.controller.*.*(..))")
    public void after(){
        log.info("AspectDemo1 after ...");
    }

    @AfterReturning("execution(* org.example.aop.controller.*.*(..))")
    public void afterReturning(){
        log.info("AspectDemo1 AfterReturning ...");
    }

    @AfterThrowing("execution(* org.example.aop.controller.*.*(..))")
    public void afterThrowing(){
        log.info("AspectDemo1 afterThrowing ...");
    }
}
